﻿using KZ.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using KZ.Express.H.Presenter;
using KZ.Express.H.ENT;

namespace KZ.Express.H
{
    public partial class LoginView : BaseView
    {
        new LoginPresenter _presenter;

        public LoginView()
        {
            InitializeComponent();
            this.TopLevel = true;
            _presenter = new LoginPresenter(this);
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                UserENT user = _presenter.Login(txtUsername.Text, txtPassword.Text);
                UserENT._USERID = user.UserID;
                UserENT._ROLEID = user.RoleID.Value;

                this.DialogResult = DialogResult.OK;
            }
            catch (BusinessLogicException ex)
            {
                ShowMessageBoxError(ex.Message);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void txtPassword_Enter(object sender, EventArgs e)
        {
            txtPassword.SelectionStart = 0;
            txtPassword.SelectionLength = txtPassword.Text.Length;
        }

        private void LoginView_Load(object sender, EventArgs e)
        {
        }
    }
}
